"""CreateAdminMenuTable Migration."""

from masoniteorm.migrations import Migration
import os


class CreateAdminMenuTable(Migration):
    def up(self):
        """
        Run the migrations.
        """
        with self.schema.create("admin_menus") as table:
            table.table_comment('菜单')
            table.increments("id")
            table.unsigned_integer('pid', False).default(0).comment('父级，admin_menu_id')
            table.unsigned_integer('rank', False).default(0).comment('排序')
            table.string('title', 255, False).comment('标题')
            table.string('uri', 100, False).default('#').comment('链接')
            table.tiny_integer('is_show', 1 ).default(0).comment('是否在菜单中显示')

            table.timestamps()
            if os.getenv("DB_CONNECTION") != "sqlite":
                table.index('pid', 'inx_pid')

    def down(self):
        """
        Revert the migrations.
        """
        self.schema.drop("admin_menus")
